﻿Ext.define('app.prm.project_task.TaskReply',
{
    extend: 'Ext.window.Window',
    autoScroll: true,
    modal: true,
    title: '答案附件',
    width: 600,
    height: 400,
    layout: 'fit',
    bodyStyle: 'padding:2px',
    projectTaskId: 0,
    initComponent: function () {
        var me = this;
        me.items = [me.getGrid()];

        me.tbar = [
            "->",
            {
                glyph: 0xf067,
                text: '新增',
                handler: function () {
                    var win = Ext.create("app.prm.project_task.ReplyNote", { projectTaskId: me.projectTaskId });
                    win.on("savesuccess", function () {
                        me.getGrid().store.load();
                        win.close();
                    });
                    win.show();
                }
            }
            //,
            //me.getUploadForm()
        ];

        me.callParent();
    },
    getUploadForm: function () {
        var me = this;
        if (!this.uploadForm) {
            this.uploadForm = new Ext.form.Panel({
                border: false,
                height: 25,
                items: [
                    {
                        xtype: 'filefield', width: 50, name: 'ProjectFile', buttonOnly: true, buttonText: '上传', listeners: {
                            change: function (btn, value, eOpts) {
                                me.uploadForm.getForm().submit({
                                    url: '/api/services/app/projectTask/UploadReply',
                                    params: { projectTaskId: me.projectTaskId },
                                    success: function (form, response) {
                                        me.getGrid().store.load({ params: { projectTaskId: me.projectTaskId } });
                                    }
                                })
                            }
                        }
                    }
                ]
            });
            return this.uploadForm;
        }
    },
    getGrid: function () {
        var me = this;
        if (!this.replyGrid) {
            this.replyGrid = new Ext.grid.Panel({
                border: true,
                viewConfig: {
                    enableTextSelection: true //可以复制单元格文字
                },
                forceFit: true,
                store: Ext.create("app.ux.PrmStore", { url: '/api/services/app/projectTask/GetReplys', filter: { projectTaskId: me.projectTaskId } }),
                columns: [
                    { header: "名称", dataIndex: 'name' },
                    {
                        header: "描述", dataIndex: 'note', renderer: function (value, p, record) {
                            p.tdAttr = 'data-qtip="' + value + '"';
                            return value;
                        }
                    },
                    {
                        header: "创建时间", dataIndex: 'createOn'
                    },
                    { header: "创建人", dataIndex: 'createBy' },
                    {
                        xtype: 'actioncolumn',
                        width: 70,
                        header: '操作',
                        items: [
                        {
                            iconCls: 'download',
                            tooltip: '下载',
                            handler: function (grid, rowIndex, colIndex) {
                                var record = grid.store.getAt(rowIndex);
                                window.location.href = '/api/services/app/document/GetFile?path=' + record.data.fullPath;
                            },
                            getClass: function (v, meta, record)
                            {
                                if (!record.data.isDownLoad) {
                                    return 'x-hidden';
                                } else
                                {
                                    return "download";
                                }
                            }
                        }
                        ]
                    }
                ]
            });
        }
        return this.replyGrid;
    }
});